package client;

import java.util.concurrent.LinkedBlockingQueue;
import communication.Message;
import communication.client.ServerHandle;

/***
 * 
 * @author malasnickik
 *
 */
public class ClientLogic implements Runnable{
	private ServerHandle serverHandle;
	
	private PaperSoccerAI paperSoccerAI;
	private LinkedBlockingQueue<Message> recievedMessages; 
	private LinkedBlockingQueue<Message> sendMessages;
	private Thread recieveThread;
	private Thread sendThread;
	private ThreadGroup commnicationThreads;
	
	
	public ClientLogic(ServerHandle serverHandle)
	{
		this.serverHandle=serverHandle;
		
	}
	

	@Override
	public void run() {
		
			Initialize();
			recieveThread.run();
			sendThread.run();
	}
	public void Initialize()
	{
		paperSoccerAI=new PaperSoccerAI("");
		commnicationThreads=new ThreadGroup("communicationThreads");
		recievedMessages=new LinkedBlockingQueue<Message>();
		sendMessages=new LinkedBlockingQueue<Message>();	
		recieveThread=new Thread(commnicationThreads,new MessageReciever(serverHandle, recievedMessages),"recieveThread");
		sendThread=new Thread(commnicationThreads,new MessageSender(serverHandle,recievedMessages, sendMessages,paperSoccerAI), "sendThread");		
	}
	
	

}
